import CodeBlock from "@theme/CodeBlock";

import CwdCreate from "!!raw-loader!./03.filesystem-cwd-create.zig";
import Stat from "!!raw-loader!./03.filesystem-stat.zig";
import MakeDirIterable from "!!raw-loader!./03.filesystem-make-dir-iterable.zig";

# Filesystem

Let's create and open a file in our current working directory, write to it, and
then read from it. Here we have to use `.seekTo` to go back to the start of the
file before reading what we have written.

<CodeBlock language="zig">{CwdCreate}</CodeBlock>

The functions
[`std.fs.openFileAbsolute`](https://ziglang.org/documentation/master/std/#std.fs.openFileAbsolute)
and similar absolute functions exist, but we will not test them here.

We can get various information about files by using `.stat()` on them. `Stat`
also contains fields for .inode and .mode, but they are not tested here as they
rely on the current OS' types.

When the Enum type is known from context, it can be omitted, so we can
compare `stat.kind` to `.file` instead of `Kind.file`.

<CodeBlock language="zig">{Stat}</CodeBlock>

We can make directories and iterate over their contents. Here we will use an
iterator (discussed later). This directory (and its contents) will be deleted
after this test finishes.

<CodeBlock language="zig">{MakeDirIterable}</CodeBlock>
